//
//  DiscoveryTableView.m
//  MagazineShangejie
//
//  Created by mac on 15/4/21.
//  Copyright (c) 2015年 CnbizMedia. All rights reserved.
//

#import "DiscoveryTableView.h"
#import "Util.h"
#import "UMSocial.h"
@interface DiscoveryTableView ()<EGORefreshTableHeaderDelegate,BDSocialUIDelegate,UIScrollViewDelegate,UITextViewDelegate>{
    BOOL reloading;//
    int _page;//页码
    BOOL isLoading;//是否在刷新
    NSMutableArray *_userData;//所有数据
    NSString*new_ID;
    NSString*cateid;
    NSString*shareTitle;
    NSString*shareUrl;
}
@property(nonatomic,strong)EGORefreshTableHeaderView * refreshHeaderView;

@end

@implementation DiscoveryTableView
@synthesize refreshHeaderView=_refreshHeaderView;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithWhite:0.890 alpha:1.000];
    [self initdata];


}
-(void)setURLString:(NSString *)URLString{
    if (URLString!=nil) {
        _URLString=URLString;
        [SVProgressHUD showWithStatus:@"数据加载中..." maskType:SVProgressHUDMaskTypeClear];
        [self loadNews];
    }
}
-(void)initdata{
    _page=1;
    EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(self.tableView.frame.origin.x,self.tableView.frame.origin.y, self.tableView.frame.size.width, 0)];
    view.delegate = self;
    [self.tableView addSubview:view];
    self.refreshHeaderView = view;


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return _userData.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger section = indexPath.section;
    NSString*type=_userData[section][@"type"];
    if ([type isEqualToString:@"comment"]) {
        return 95;
    }else{
        return 115;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell ;
    if(indexPath.section == [_userData count]-2){
        [SVProgressHUD showWithStatus:@"数据加载中..." maskType:SVProgressHUDMaskTypeClear];
        [self loadNews];
    }
    int type ;
    if ([self.URLString isEqualToString:@"System/Found"]) {
        type=2;
    }else{
        if ([_userData[indexPath.section][@"description"] length]>0) {
            type=1;
        }else{
            type=5;
        }
    }
    if (type==1) {
        cell= [tableView dequeueReusableCellWithIdentifier:@"cell1"];
        if (cell==nil) {
            cell=[tableView dequeueReusableCellWithIdentifier:@"cell1"  forIndexPath:indexPath];
            
        }
    }else if (type==2) {
        cell= [tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath];
        if (cell==nil) {
            cell=[tableView dequeueReusableCellWithIdentifier:@"cell2"];
        }
    }else if (type==3) {
        cell= [tableView dequeueReusableCellWithIdentifier:@"cell3" forIndexPath:indexPath];
        if (cell==nil) {
            cell=[tableView dequeueReusableCellWithIdentifier:@"cell3"];
        }
    }else if (type==4) {
        cell= [tableView dequeueReusableCellWithIdentifier:@"cell4" forIndexPath:indexPath];
        if (cell==nil) {
            cell=[tableView dequeueReusableCellWithIdentifier:@"cell4"];
        }
    }else if (type==5) {
        cell= [tableView dequeueReusableCellWithIdentifier:@"cell5" forIndexPath:indexPath];
        if (cell==nil) {
            cell=[tableView dequeueReusableCellWithIdentifier:@"cell5"];
        }
    }
    [cell.contentView setTag:indexPath.section];
    UIImage*image=[[SDImageCache sharedImageCache] imageFromDiskCacheForKey:_userData[indexPath.section][@"thumb"]];
    if(image==nil){
      [[[UIImageView alloc]init] sd_setImageWithURL:[NSURL URLWithString:_userData[indexPath.section][@"thumb"]]];
    }
    
    if (type==1) {
        return [self LoadDataType1:tableView Cell:cell IndexPath:indexPath];
    }else if (type==2) {
        return [self LoadDataType2:tableView Cell:cell IndexPath:indexPath];
    }else if (type==3) {
        return [self LoadDataType3:tableView Cell:cell IndexPath:indexPath];
    }else if (type==4) {
        return [self LoadDataType4:tableView Cell:cell IndexPath:indexPath];
    }else if (type==5) {
        return [self LoadDataType5:tableView Cell:cell IndexPath:indexPath];
    }else{
        return cell;
    }
    
    return cell;
}
-(UITableViewCell *)LoadDataType1:(UITableView*)tableView Cell:(UITableViewCell*)cell IndexPath:(NSIndexPath *)indexPath {
    
    UIImageView*imageview=(UIImageView *)[cell.contentView viewWithTag:511];
    [imageview setImage:[UIImage imageNamed:@"icon_default_ipad"]];
    [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:_userData[indexPath.section][@"thumb"]] options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        if (image==nil) {
            [imageview setImage:[UIImage imageNamed:@"icon_default_ipad"]];
        }else{
            [imageview setImage:image];
        }
    }];
    UILabel*label1=(UILabel*)[cell.contentView viewWithTag:522];
    label1.text=_userData[indexPath.section][@"title"];
    
    UILabel*label5=(UILabel*)[cell.contentView viewWithTag:533];
    label5.text=[NSString stringWithFormat:@"%@",_userData[indexPath.section][@"description"]];

    UILabel*label2=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:544];
    label2.text=[NSString stringWithFormat:@"评论(%@)",_userData[indexPath.section][@"comment"]];
    UILabel*label3=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:555];
    label3.text=[NSString stringWithFormat:@"赞(%@)",_userData[indexPath.section][@"like"]];
    UILabel*label4=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:566];
    label4.text=[NSString stringWithFormat:@"转发(%@)",_userData[indexPath.section][@"fw"]];
    
    return cell;
}
-(UITableViewCell *)LoadDataType2:(UITableView*)tableView Cell:(UITableViewCell*)cell IndexPath:(NSIndexPath *)indexPath {
    //    NSLog(@"row---%d",indexPath.row);
    UIImageView*imageview=(UIImageView*)[cell.contentView viewWithTag:511];
    
    [imageview.layer setMasksToBounds:YES];
    imageview.layer.cornerRadius = CGRectGetHeight(imageview.frame) / 2.0f;
    NSString*url=[NSString stringWithFormat:@"%@",_userData[indexPath.section][@"avatar"]];
    [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:url] options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        if (image==nil) {
            [imageview setImage:[UIImage imageNamed:@"icon_default_ipad"]];
        }else{
            [imageview setImage:image];
        }
    }];
    
    UILabel*label1=(UILabel*)[cell.contentView viewWithTag:522];
    label1.text=[NSString stringWithFormat:@"%@ 赞 %@",_userData[indexPath.section][@"nickname"],_userData[indexPath.section][@"title"]];
    NSString*username=[NSString stringWithFormat:@"%@ 赞",_userData[indexPath.section][@"nickname"]];
    NSString*like=@"赞";
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:label1.text];
    [attriString addAttributes:@{ NSForegroundColorAttributeName:[UIColor redColor]} range:NSMakeRange(0, username.length - like.length)];
    [attriString addAttributes:@{ NSForegroundColorAttributeName:[UIColor colorWithWhite:0.530 alpha:1.000]} range:NSMakeRange(username.length - like.length, like.length)];
    label1.attributedText=attriString;
    
    UILabel*label2=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:544];
    label2.text=[NSString stringWithFormat:@"评论(%@)",_userData[indexPath.section][@"comment"]];
    UILabel*label3=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:555];
    label3.text=[NSString stringWithFormat:@"赞(%@)",_userData[indexPath.section][@"like"]];
    UILabel*label4=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:566];
    label4.text=[NSString stringWithFormat:@"转发(%@)",_userData[indexPath.section][@"fw"]];
    
    return cell;
}
-(UITableViewCell *)LoadDataType3:(UITableView*)tableView Cell:(UITableViewCell*)cell IndexPath:(NSIndexPath *)indexPath {
    UIImageView*imageview=(UIImageView *)[cell.contentView viewWithTag:511];
    [imageview setImage:[UIImage imageNamed:@"icon_default_ipad"]];
    [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:_userData[indexPath.section][@"thumb"]] options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        if (image==nil) {
            [imageview setImage:[UIImage imageNamed:@"icon_default_ipad"]];
        }else{
            [imageview setImage:image];
        }
    }];
    UILabel*label1=(UILabel*)[cell.contentView viewWithTag:522];
    label1.text=_userData[indexPath.section][@"title"];
    
    UILabel*label5=(UILabel*)[cell.contentView viewWithTag:533];
    label5.text=[NSString stringWithFormat:@"%@",_userData[indexPath.section][@"description"]];
    
    UILabel*label2=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:544];
    label2.text=[NSString stringWithFormat:@"评论(%@)",_userData[indexPath.section][@"comment"]];
    UILabel*label3=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:555];
    label3.text=[NSString stringWithFormat:@"赞(%@)",_userData[indexPath.section][@"like"]];
    UILabel*label4=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:566];
    label4.text=[NSString stringWithFormat:@"转发(%@)",_userData[indexPath.section][@"fw"]];
    
    return cell;
}
-(UITableViewCell *)LoadDataType4:(UITableView*)tableView Cell:(UITableViewCell*)cell IndexPath:(NSIndexPath *)indexPath {
    UIImageView*imageview=(UIImageView *)[cell.contentView viewWithTag:511];
    [imageview setImage:[UIImage imageNamed:@"icon_default_ipad"]];
    [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:_userData[indexPath.section][@"thumb"]] options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        if (image==nil) {
            [imageview setImage:[UIImage imageNamed:@"icon_default_ipad"]];
        }else{
            [imageview setImage:image];
        }
    }];
    UILabel*label1=(UILabel*)[cell.contentView viewWithTag:522];
    label1.text=_userData[indexPath.section][@"title"];
    
    UILabel*label5=(UILabel*)[cell.contentView viewWithTag:533];
    label5.text=[NSString stringWithFormat:@"%@",_userData[indexPath.section][@"description"]];
    
    UILabel*label2=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:544];
    label2.text=[NSString stringWithFormat:@"评论(%@)",_userData[indexPath.section][@"comment"]];
    UILabel*label3=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:555];
    label3.text=[NSString stringWithFormat:@"赞(%@)",_userData[indexPath.section][@"like"]];
    UILabel*label4=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:566];
    label4.text=[NSString stringWithFormat:@"转发(%@)",_userData[indexPath.section][@"fw"]];
    
    return cell;
}
-(UITableViewCell *)LoadDataType5:(UITableView*)tableView Cell:(UITableViewCell*)cell IndexPath:(NSIndexPath *)indexPath {
    UIImageView*imageview=(UIImageView *)[cell.contentView viewWithTag:511];
    [imageview setImage:[UIImage imageNamed:@"icon_default_ipad"]];
    [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:_userData[indexPath.section][@"thumb"]] options:SDWebImageRefreshCached progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        if (image==nil) {
            [imageview setImage:[UIImage imageNamed:@"icon_default_ipad"]];
        }else{
            [imageview setImage:image];
        }
    }];
    UILabel*label1=(UILabel*)[cell.contentView viewWithTag:522];
    label1.text=_userData[indexPath.section][@"title"];
    UILabel*label2=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:544];
    label2.text=[NSString stringWithFormat:@"评论(%@)",_userData[indexPath.section][@"comment"]];
    UILabel*label3=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:555];
    label3.text=[NSString stringWithFormat:@"赞(%@)",_userData[indexPath.section][@"like"]];
    UILabel*label4=(UILabel*)[[cell.contentView viewWithTag:1234] viewWithTag:566];
    label4.text=[NSString stringWithFormat:@"转发(%@)",_userData[indexPath.section][@"fw"]];
    
    return cell;
}



- (IBAction)comment:(id)sender {
//    NSLog(@"%ld——————tag%ld",[sender tag],[[sender superview] tag]);
    [self isLogin];
    NSString*url=_userData[[[[sender superview] superview] tag]][@"url"];
    NSArray*ksjv2=[url componentsSeparatedByString:@"ksjv2.kanshangjie.com"];
    if (ksjv2.count<2) {
        return;
    }
    NSArray *arr = [url componentsSeparatedByString:@"?"];
    NSArray*arr1=[arr[1] componentsSeparatedByString:@"&"];
    for (NSString*str in arr1) {
        NSArray*strA=[str componentsSeparatedByString:@"="];
        if ([strA[0] isEqualToString:@"catid"]) {
            cateid=strA[1];
        }else if ([strA[0] isEqualToString:@"id"]) {
            new_ID=strA[1];
        }
        if(new_ID!=nil&&cateid!=nil){
            break;
        }
    }
    if (self.DiscoveryCommentBlcok) {
        self.DiscoveryCommentBlcok(new_ID,cateid);
    }
}
- (IBAction)like:(id)sender {
    
    NSString*likeID;
    NSString*url=_userData[[[[sender superview] superview] tag]][@"url"];

    NSArray*ksjv2=[url componentsSeparatedByString:@"ksjv2.kanshangjie.com"];
    if (ksjv2.count<2) {
        return;
    }
    NSArray *arr = [url componentsSeparatedByString:@"?"];
    NSArray*arr1=[arr[1] componentsSeparatedByString:@"&"];
    for (NSString*str in arr1) {
        NSArray*strA=[str componentsSeparatedByString:@"="];
        if ([strA[0] isEqualToString:@"catid"]) {
            cateid=strA[1];
        }else if ([strA[0] isEqualToString:@"id"]) {
            likeID=strA[1];
        }
        if(likeID!=nil&&cateid!=nil){
            break;
        }
    }
    UILabel*like=(UILabel*)[[[[sender superview] superview] viewWithTag:1234] viewWithTag:555];
    NSInteger tag=[[[sender superview] superview] tag];
    like.text=[NSString stringWithFormat:@"赞(%d)",[[self UserDataOfTag:tag][@"like"] intValue]+1];
    [self likeAnimateWithDuration:like];
//   __weak typeof(self) unself = self;
    [[AppAPIClient sharedClient] POST:@"Comment/Attitude" parameters:@{@"d": @"1",@"catid":cateid,@"id":likeID} success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        UILabel*like=(UILabel*)[[[[sender superview] superview] viewWithTag:1234] viewWithTag:555];
//        NSInteger tag=[[[sender superview] superview] tag];
//        like.text=[NSString stringWithFormat:@"赞(%d)",[[unself UserDataOfTag:tag][@"like"] intValue]+1];
//        [unself likeAnimateWithDuration:like];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}
- (IBAction)fw:(id)sender {
    [SVProgressHUD show];
    NSDictionary*dic = [[NSDictionary alloc] init];
    dic =_userData[[[[sender superview] superview] tag]];
    shareTitle = dic[@"title"];
    shareUrl   = dic[@"url"];
    BDSocialShareContent *content = [BDSocialShareContent shareContentWithDescription:dic[@"description"] url:dic[@"url"] title:dic[@"title"]];
    //    [content addImageWithThumbImage:[UIImage imageNamed:@"icon_default_ipad"] imageUrl:self._Dict[@"thumb"]];
    UIImageView*imageview=[[UIImageView alloc]init];
    [imageview sd_setImageWithURL:[NSURL URLWithString:dic[@"thumb"]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image==nil) {
            [content addImageWithThumbImage:[UIImage imageNamed:@"icon_default_ipad"] imageSource:[UIImage imageNamed:@"icon_default_ipad"]];
        }else{
            [content addImageWithThumbImage:image imageSource:image];
        }
        [SVProgressHUD dismiss];
        //分享
        [UMSocialSnsService presentSnsIconSheetView:self
                                             appKey:nil
                                          shareText:[NSString stringWithFormat:@"%@",dic[@"title"] ]
                                         shareImage:[UIImage imageNamed:@"icon"]
                                    shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToQQ,UMShareToQzone,UMShareToWechatTimeline,UMShareToWechatSession,UMShareToTencent,UMShareToEmail,UMShareToSms,nil]
                                           delegate:self];
        [UMSocialData defaultData].extConfig.sinaData.urlResource.url = dic[@"url"];
        [UMSocialData defaultData].extConfig.qqData.url = dic[@"url"];
        [UMSocialData defaultData].extConfig.qzoneData.url = dic[@"url"];
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = dic[@"url"];
        [UMSocialData defaultData].extConfig.wechatSessionData.url = dic[@"url"];
        
        [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatSession,UMShareToWechatTimeline]];
    }];
    
}

-(void)didSelectSocialPlatform:(NSString *)platformName withSocialData:(UMSocialData *)socialData
{
    if (platformName == UMShareToSina) {
        socialData.shareText = [NSString stringWithFormat:@"%@ %@",shareTitle,shareUrl];
    }
    else{
        socialData.shareText = [NSString stringWithFormat:@"%@",shareTitle ];
    }
}
-(void)isLogin{
    if (![UserDefaults objectForKey:@"user"]) {
        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
        [self.navigationController pushViewController:login animated:YES];
        return;
    }
}
-(NSDictionary*)UserDataOfTag:(NSInteger)tag{
    return _userData[tag];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:NO];//点击后不会有阴影
    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ArticleViewController*art=[story instantiateViewControllerWithIdentifier:@"ArticleViewController"];
    art._Dict=_userData[indexPath.section];
    art.isCommentVC=NO;
    art.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:art animated:YES completion:^{

    }];
    
}
#pragma mark - 点赞动画
-(void)likeAnimateWithDuration:(UIView*)view{
    [UIView animateWithDuration:.3
     
                     animations:^{
                         
                         view.transform = CGAffineTransformMakeScale(1.2, 1.2);
                         
                     }completion:^(BOOL finish){
                         
                         [UIView animateWithDuration:.3
                          
                                          animations:^{
                                              
                                              view.transform = CGAffineTransformMakeScale(0.9, 0.9);
                                              
                                          }completion:^(BOOL finish){
                                              
                                              [UIView animateWithDuration:.3
                                               
                                                               animations:^{
                                                                   
                                                                   view.transform = CGAffineTransformMakeScale(1, 1);
                                                                   
                                                               }completion:^(BOOL finish){
                                                                   
                                                                   
                                                                   
                                                               }];
                                              
                                          }];
                         
                     }];
}



#pragma mark - 网络数据请求方法
-(void)loadNews{
    NSLog(@"开始加载");
    
    if(isLoading){
        [SVProgressHUD dismiss];
        return;
    }
    isLoading = YES;

    [[AppAPIClient sharedClient] GET:self.URLString parameters:@{@"p":[NSString stringWithFormat:@"%d",_page]} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSMutableArray *result = responseObject[@"data"];
        if([result isKindOfClass:[NSNull class]] || [result count] == 0){

            [SVProgressHUD dismiss];
            [self.tableView reloadData];
            [self.refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
            reloading = NO;
            return;
        }
        if(_userData.count==0){
            _userData = [[NSMutableArray alloc]initWithArray:result copyItems:YES];
        }else{
            [_userData addObjectsFromArray:result];
        }
        _page++;

        
        isLoading = NO;
        [SVProgressHUD dismiss];
        
        reloading = NO;
        [self.refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
        [self.tableView reloadData];
        NSLog(@"加载完成");
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"ERR: %@",operation.responseString);
        isLoading = NO;
        reloading = NO;
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
        [self.refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
    }];
}
#pragma mark - UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    [self.refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    
    [self.refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    
}
#pragma mark RefreshHeaderViewDelegate Methods

-(void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView *)view{
    
    
    if(reloading){
        return;
    }
    reloading=YES;
    NSLog(@"重新加载");
    [self performSelector:@selector(doneLoadingViewData) withObject:nil afterDelay:0];
    
}
- (void)doneLoadingViewData{

    _page=1;
    _userData = nil;
    [self.tableView reloadData];
    [self loadNews];
    
    
    
}
-(BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView *)view{
    return reloading;
}
-(NSDate *)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView *)view{
    return [NSDate date];
}

@end
